package com.android.aqq;

import com.android.aqq.util.Utils;

import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.Preference.OnPreferenceChangeListener;

public class aQQPref extends PreferenceActivity {
	private final static String[] prefs = new String[]{"server_preference","customer_server_preference"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preferences);
        
        for (int i=0; i<prefs.length; i++) {
        	Preference pref = findPreference(prefs[i]);
        	pref.setOnPreferenceChangeListener(new OnPreferenceChangeListener(){
    			public boolean onPreferenceChange(Preference preference,
    					Object newValue) {
    				String key = preference.getKey();
    				if ("".equals(newValue)) {
    					preference.setSummary(Utils.getResourceStringId("summary" + "_" + key));
    				} else {
    					preference.setSummary(newValue.toString());
    				}
    				return true;
    			}
    		});
        }
        final Preference pref = findPreference("vibrate_preference");
        pref.setOnPreferenceChangeListener(new OnPreferenceChangeListener(){
			public boolean onPreferenceChange(Preference preference,
					Object newValue) {
				if ((Boolean)newValue) {
					preference.setSummary("静音时震动提醒");
				} else {
					preference.setSummary("静音时不震动");
				}
				return true;
			}
		});
    }

	@Override
	protected void onStart() {
		super.onStart();
		
        for (int i=0; i<prefs.length; i++) {
        	Preference pref = findPreference(prefs[i]);
        	String value = pref.getSharedPreferences().getString(prefs[i],"");
        	if ("".equals(value)) {
        		pref.setSummary(Utils.getResourceStringId("summary" + "_" + prefs[i]));
        	} else {
        		pref.setSummary(value);
        	}
        }
        
        Preference pref = findPreference("vibrate_preference");
        if (pref.getSharedPreferences().getBoolean("vibrate_preference", false)) {
        	pref.setSummary("静音时震动提醒");
		} else {
			pref.setSummary("静音时不震动");
		}
	}
	
	@Override
	protected void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
	}
    
}
